package com.atguigu.tingshu.account.listener;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountReceiver {

    @Autowired
    private UserAccountService userAccountService;

    @KafkaListener(topics = KafkaConstant.QUEUE_USER_REGISTER)
    public void AccountReceiver(ConsumerRecord<String, String> record){
        String value = record.value();
        if (StringUtils.isNotBlank(value)) {
            log.info("[账户服务]监听用户注册成功消息：{}", value);
            Long userId = Long.valueOf(value);
            userAccountService.saveUserAccount(userId);
        }
    }
}
